package com.baibei.ebec.user.systemmessage;

import android.content.Context;

import com.baibei.basic.BasicPresenterImpl;
import com.baibei.basic.module.observer.PageDataObservable;
import com.baibei.ebec.sdk.ApiFactory;
import com.baibei.ebec.sdk.IMessageApi;
import com.baibei.ebec.sdk.IOrderApi;
import com.baibei.ebec.sdk.IUserApi;
import com.baibei.model.MessageInfo;
import com.baibei.model.MsgInfo;
import com.baibei.model.OrderInfo;
import com.baibei.sdk.ApiDefaultObserver;
import com.blankj.utilcode.utils.LogUtils;

import java.util.List;

import io.reactivex.Observable;

public class SystemMessagePresenterImpl extends BasicPresenterImpl<SystemMessageContract.SystemMessageView> implements SystemMessageContract.Presenter {
    private final IUserApi iUserApi;

//    IMessageApi messageApi;
//    private List<MessageInfo> mOrderLists;
//    PageDataObservable<MessageInfo> orderInfoPageDataObservable;
//
//    public SystemMessagePresenterImpl(Context context, SystemMessageContract.SystemMessageView view) {
//        super(context, view);
//        messageApi = ApiFactory.getInstance().getMessageApi();
//        orderInfoPageDataObservable = new PageDataObservable<MessageInfo>(mView) {
//            @Override
//            protected Observable<List<MessageInfo>> onCreateObserver(int page) {
//                return createObservable(messageApi.getMessageList(page));
//            }
//
//            @Override
//            protected void onLoadDataComplete(List<MessageInfo> dataList) {
//                super.onLoadDataComplete(dataList);
//                mOrderLists=dataList;
//                mView.hideRefreshLayout();
//            }
//
//            @Override
//            protected void onNoMoreData() {
//                super.onNoMoreData();
//                mView.hideRefreshLayout();
//            }
//        };
//    }
//
//    @Override
//    public void start() {
//        super.start();
//        if (orderInfoPageDataObservable!=null){
//            orderInfoPageDataObservable.start();
//        }
//    }
//
//
//    @Override
//    public void loadMore() {
//        orderInfoPageDataObservable.loadMore();
//    }

    public SystemMessagePresenterImpl(Context context, SystemMessageContract.SystemMessageView view) {
        super(context, view);
        iUserApi = ApiFactory.getInstance().getUserApi();
    }

    @Override
    public void getMsgList(String userId, String accessToken) {
        createObservable(iUserApi.getSysMsg(userId,accessToken)).subscribe(new ApiDefaultObserver<List<MsgInfo>>() {
            @Override
            protected void onError(String s) {

            }

            @Override
            protected void accept(List<MsgInfo> msgInfos) {
                mView.onLoadMsg(msgInfos);
                mView.hideRefreshLayout();
            }
        });
    }
}
